package demo1;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


public class DemoServlet extends HelloServlet{
    @Override
    protected void doGet(
            HttpServletRequest req, HttpServletResponse resp
            )throws ServletException , IOException{
        resp.setContentType("text/html;charset=UTF-8");
        //获取当前DemoServlet的ServletConfig对象
        ServletConfig config =this.getServletConfig();
        String sName =config.getServletName();
//        System.out.println(sName);
//        resp.getWriter().write(sName);
        ServletContext context=this.getServletContext();
        String str=(String) context.getAttribute("str");
        resp.getWriter().write("从context中取出数据"+str);
    }
}
